﻿///////////////////////////////////////////////////////////////////////////////
//
// This file is part of the BassDrop project
//   https://code.google.com/p/bass-drop/
//
//
// Creator:	Gergely Krajcsovszki (krajcsovszkig@hotmail.com)
// Date:	2013-08-05 12:55
//
//
// Copyright © 2013-2014. Gergely Krajcsovszki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BassDrop.Core.Common.Options.Items
{
	/// <summary>
	/// OptionsItem for setting properties
	/// </summary>
	/// <typeparam name="T">type of the property to set</typeparam>
	public abstract class PropertyOptionsItem<T> : OptionsItemBase
	{
		/// <summary>
		/// Delegate type for property setters that are called when
		/// the value changes.
		/// </summary>
		/// <param name="value">The new value of the property</param>
		public delegate void SetActionDelegate( T value );

		/// <summary>
		/// Delegate type for property getters that are called on initialization.
		/// </summary>
		/// <returns>The current value of the property.</returns>
		public delegate T GetActionDelegate();

		/// <summary>
		/// Method called when the property value changed.
		/// </summary>
		protected SetActionDelegate SetAction
		{
			get;
			private set;
		}

		/// <summary>
		/// Method called to read the current value of the property from the plugin.
		/// </summary>
		protected GetActionDelegate GetAction
		{
			get;
			private set;
		}

		/// <summary>
		/// Creates a new property setter options item
		/// </summary>
		/// <param name="setAction">Method called when the property value changed.</param>
		/// <param name="getAction">Method called to read the current value of the property from the plugin.</param>
		/// <param name="name">Name/title of the item</param>
		/// <param name="description">The description of the item. Shown typically in tooltips</param>
		protected PropertyOptionsItem(
			SetActionDelegate setAction,
			GetActionDelegate getAction,
			string name,
			string description )
			: base( name, description )
		{
			SetAction = setAction;
			GetAction = getAction;
		}

		/// <summary>
		/// Returns the current value of the property
		/// </summary>
		/// <returns></returns>
		public T GetValue()
		{
			return GetAction();
		}

		/// <summary>
		/// Sets the value of the property
		/// </summary>
		/// <param name="value"></param>
		public void SetValue( T value )
		{
			SetAction( value );
		}
	}
}
